package com.rc.evcharger.common.mapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Map;


/**
 * @Author: yang
 * @Date: 2022/4/28 15:29
 */
public class ObjectMapperSingletonUtil {

    public static ObjectMapper objectMapper;

    public static ObjectMapper getInstance() {
        if (objectMapper == null) {
            return objectMapper = new ObjectMapper();
        }
        return objectMapper;
    }


    public static void main(String[] args) throws JsonProcessingException {

        Map map = new HashMap();
        map.put("aaa",1234);
        //json解析与封装
        String s = ObjectMapperSingletonUtil.getInstance().writeValueAsString(map);
        System.out.println(s);
        Map map1 = ObjectMapperSingletonUtil.getInstance().readValue(s, Map.class);
        System.out.println(map1.get("aaa"));
    }
}
